home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 October / CHIP Turkiye Ekim 2000.iso / prog / naps / 04 / setup.exe / Gnucleus / PrefDialog.cpp < prev    next >
C/C++ Source or Header  |  2000-06-28  |  6KB  |  226 lines

  1. /********************************************************************************
  2.  
  3.     Gnucleus - A node application for the Gnutella network
  4.     Copyright (C) 2000 John Marshall
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; either version 2 of the License.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18.  
  19.     For support, questions, comments, etc...
  20.     E-Mail: 
  21.         swabby@c0re.net
  22.     
  23.     Address:
  24.         21 Cadogan Way
  25.         Nashua, NH, USA 03062
  26.  
  27. ********************************************************************************/
  28.  
  29. // PrefDialog.cpp : implementation file
  30. //
  31.  
  32. #include "stdafx.h"
  33. #include "Gnucleus.h"
  34. #include "GnucleusDoc.h"
  35.  
  36. #include "PrefDialog.h"
  37.  
  38. #ifdef _DEBUG
  39. #define new DEBUG_NEW
  40. #undef THIS_FILE
  41. static char THIS_FILE[] = __FILE__;
  42. #endif
  43.  
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CPrefDialog
  46.  
  47. IMPLEMENT_DYNAMIC(CPrefDialog, CPropertySheet)
  48.  
  49. CPrefDialog::CPrefDialog(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
  50.     :CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
  51. {
  52. }
  53.  
  54. CPrefDialog::CPrefDialog(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
  55.     :CPropertySheet(pszCaption, pParentWnd, iSelectPage)
  56. {
  57.     AddPages();
  58. }
  59.  
  60. CPrefDialog::~CPrefDialog()
  61. {
  62.     ((CGnucleusDoc *) ((CGnucleusApp *) AfxGetApp())->MasterDoc)->WriteINI();
  63. }
  64.  
  65. void CPrefDialog::AddPages()
  66. {
  67.     // Don't load the help button, maybe later we can put help in
  68.     m_hIcon = AfxGetApp()->LoadIcon(IDR_DEBUG);
  69.     m_psh.dwFlags |= PSP_USEHICON;
  70.     m_psh.hIcon = m_hIcon;
  71.  
  72.     m_psh.dwFlags &= ~PSH_HASHELP;
  73.  
  74.     // Add Tabs
  75.     AddPage(&m_TabConnect);
  76.     AddPage(&m_TabSearch);
  77.     AddPage(&m_TabDownload);
  78.     AddPage(&m_TabUpload);
  79.     AddPage(&m_TabBandwidth);
  80.     AddPage(&m_TabLanguage);
  81.     
  82.     // Disable the tabs, so we can use the tree control.
  83.     //this->SetWizardMode();
  84. }
  85.  
  86. BEGIN_MESSAGE_MAP(CPrefDialog, CPropertySheet)
  87.     //{{AFX_MSG_MAP(CPrefDialog)
  88.     ON_WM_CREATE()
  89.     //}}AFX_MSG_MAP
  90.     ON_NOTIFY(TVN_SELCHANGED, IDC_PREF_TREE, OnSelchanged)
  91.     ON_MESSAGE(WM_NOTIFYFORMAT, OnNotifyFormat)
  92.     ON_COMMAND(ID_APPLY_NOW, OnApplyNow)
  93. END_MESSAGE_MAP()
  94.  
  95. /////////////////////////////////////////////////////////////////////////////
  96. // CPrefDialog message handlers
  97.  
  98. BOOL CPrefDialog::OnInitDialog() 
  99. {
  100.     BOOL bResult = CPropertySheet::OnInitDialog();
  101.     
  102.     SetIcon(m_hIcon, TRUE);
  103.     SetIcon(m_hIcon, FALSE);
  104.  
  105.     // Disable the tabs, so we can use the tree control.
  106.     GetTabControl()->ShowWindow(SW_HIDE);
  107.     
  108.     // Setup the tree control dynamicly    
  109.     CRect rectWnd, rectTree;
  110.     GetWindowRect(rectWnd);
  111.     ScreenToClient(rectWnd);
  112.  
  113.     rectTree.SetRect(PREF_TREE_MARGIN_LEFT, PREF_TREE_MARGIN_TOP, 
  114.         PREF_TREE_MARGIN_LEFT + PREF_TREE_WIDTH, rectWnd.bottom - PREF_TREE_MARGIN_BOTTOM );
  115.  
  116.     BOOL bCreateResult = m_Tree.Create( WS_VISIBLE | WS_TABSTOP | WS_CHILD | WS_BORDER |
  117.         TVS_LINESATROOT | TVS_HASLINES | TVS_LINESATROOT | TVS_SHOWSELALWAYS,
  118.         rectTree, this , IDC_PREF_TREE);
  119.  
  120. //    m_Tree.ModifyStyleEx(0, WS_EX_WINDOWEDGE);
  121.     
  122.     // Flesh out the tree control.
  123.  
  124.     m_Tree.SelectItem(m_Tree.InsertItem("Connect"));        // select the first item
  125.     m_Tree.InsertItem("Search");
  126.     m_Tree.InsertItem("Download");
  127.     m_Tree.InsertItem("Share");
  128.     m_Tree.InsertItem("Bandwidth");
  129.     m_Tree.InsertItem("Language");
  130.  
  131.     //save rect for property pages
  132.     GetActivePage()->GetWindowRect(m_rectPage);
  133.     ScreenToClient(m_rectPage);
  134.  
  135.     return bResult;
  136. }
  137.  
  138. int CPrefDialog::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  139. {
  140.     if (CPropertySheet::OnCreate(lpCreateStruct) == -1)
  141.         return -1;
  142.  
  143.     CRect rectWnd;
  144.     GetWindowRect(rectWnd);
  145.  
  146.     // add space for the tree control to the width of the dialog box.
  147.     rectWnd.right += PREF_TREE_WIDTH + PREF_TREE_MARGIN_LEFT + PREF_TREE_MARGIN_RIGHT;
  148.  
  149.     MoveWindow(rectWnd);
  150.     CenterWindow(NULL);
  151.  
  152.  
  153.  
  154.     return 0;
  155. }
  156.  
  157. ////////////////////////////////////////////////////////////
  158. //! author="Nathan Brown"
  159. //
  160. // Switches property sheets on selection of item in the tree view
  161. void CPrefDialog::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult) 
  162. {
  163.     NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  164.     *pResult = 0;
  165.  
  166.     HTREEITEM htItem = m_Tree.GetSelectedItem();
  167.  
  168.     if(htItem != NULL)
  169.     {
  170.         CString str_item_text = m_Tree.GetItemText(htItem);
  171.         
  172.         if( str_item_text == "Connect")
  173.             SetActivePage(&m_TabConnect);
  174.         else if( str_item_text == "Search")
  175.             SetActivePage(&m_TabSearch);
  176.         else if( str_item_text == "Download")
  177.             SetActivePage(&m_TabDownload);
  178.         else if( str_item_text == "Share")
  179.             SetActivePage(&m_TabUpload);
  180.         else if( str_item_text == "Bandwidth")
  181.             SetActivePage(&m_TabBandwidth);
  182.         else if( str_item_text == "Language")
  183.             SetActivePage(&m_TabLanguage);
  184.  
  185.         // Set the title
  186.         SetTitle((LPCTSTR)str_item_text, PSH_PROPTITLE);
  187.     }
  188.  
  189.     CRect rectWnd;
  190.     // Move window around because of tree control and no tabs.
  191.     GetActivePage()->GetWindowRect(rectWnd);
  192.     ScreenToClient(rectWnd);
  193.     // move over and up
  194.     rectWnd.OffsetRect( PREF_TREE_MARGIN_LEFT + PREF_TREE_WIDTH + PREF_TREE_MARGIN_RIGHT,
  195.         -PREF_TAB_OFFSET_UP);
  196.     GetActivePage()->MoveWindow(rectWnd);
  197.  
  198.     
  199.  
  200. }
  201.  
  202. ////////////////////////////////////////////////////////////
  203. //! author="Nathan Brown"
  204. //
  205. // Fix for confirmed bug in NT (Q148533) for control using 
  206. // UNICODE messages when it shouldn't.
  207. LRESULT CPrefDialog::OnNotifyFormat(WPARAM wParam, LPARAM lParam)
  208. {
  209. #ifdef _UNICODE
  210.     return NFR_UNICODE;
  211. #else
  212.     return NFR_ANSI;
  213. #endif
  214.  
  215. ////////////////////////////////////////////////////////////
  216. //! author="Nathan Brown"
  217. //
  218. // Intercep the Apply Now command, and correct the positioning.
  219. void CPrefDialog::OnApplyNow()
  220. {
  221.     Default();
  222.  
  223.     GetActivePage()->MoveWindow(m_rectPage);
  224. }
  225.